package com.example.system.controller;


import com.example.common.auth.CheckLogin;
import com.example.common.response.SystemResponse;
import com.example.system.dto.AuthorizedLoginDTO;
import com.example.system.service.IUserService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yoonada
 * @since 2020-10-28
 */
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class UserController {

    private final IUserService userService;

    /**
     * 授权登录
     * @param authorizedLoginDTO
     * @return
     */
    @PostMapping("/authorizedLogin")
    public SystemResponse authorizedLogin(@RequestBody AuthorizedLoginDTO authorizedLoginDTO){
        return userService.authorizedLogin(authorizedLoginDTO);
    }

    /**
     * 获取小程序的openId
     * @param code
     * @return
     * @throws Exception
     */
    @PostMapping("/getOpenId")
    public SystemResponse getOpenId(String code) throws Exception {
        return userService.getOpenId(code);
    }

    /**
     * 微信登录
     * @param code
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/wxLogin")
    public SystemResponse wxLogin(String code) throws Exception {
        return userService.wxLogin(code);
    }

    @CheckLogin
    @ApiOperation("获取用户信息")
    @GetMapping("/getUserInfo")
    public SystemResponse getUserInfo(){
        return userService.getUserInfo();
    }

}
